Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

455
Vistas
React.Lazy usage throws "Expression produces a union type that is too complex to represent"

I am trying to develop a simple application with two different components. The main one uses React.lazy to get the other component and wraps it inside a React.Suspense element. But there is a super weird error in this simple example and a more abnormal hacky solution.

The error is: Expression produces a union type that is too complex to represent

The source code is below. And I also created a repository that you can easily repeat the error yourself.

App.tsx contents

import React from "react"
import ReactDom from "react-dom"

const Fr = React.lazy(
    () => import('./Fragment')
);

// Uncomment this line below, then it compiles without any errors
// const dummy = <Fr />

const Main = () => (
    <div>
        <React.Suspense fallback={"Loading"}>
            <div>
                <Fr/> {/* Error:  Expression produces a union type that is too complex to represent */}
            </div>
        </React.Suspense>
    </div>
)

// @ts-ignore
ReactDom.render(<Main/>, document.body);

As you can see App.tsx imports ./Fragment with React.lazy. And when using the Fr component, typescript throws the error.

Fragment.tsx contents

import * as React from "react"

const Fragment = () => (
    <div>
        Fragment
    </div>
)

export default Fragment

When using Typescript 4.1.2, it works without any error, but in 4.5.2, it is not.

Weird Solution

When you uncomment the dummy assignment const dummy = <Fr />, it works without any problem.

Now I am wondering what is the actual problem here and why the dummy assignment solves it?

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda